package org.yzz.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.yzz.base.mapper.BaseMapper;
import org.yzz.base.query.BaseQuery;
import org.yzz.base.service.IBaseService;
import org.yzz.base.utils.PageInfo;
import java.io.Serializable;
import java.util.List;

@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class BaseServiceImpl<T> implements IBaseService<T> {
    
    @Autowired
    private BaseMapper<T> mapper;
    
    @Override
    public List<T> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public T selectById(Serializable id) {
        return mapper.selectById(id);
    }

    @Override
    @Transactional
    public void insert(T t) {
        mapper.insert(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Serializable id) {
        mapper.delete(id);
    }

    @Override
    public PageInfo<T> queryPage(BaseQuery baseQuery) {
        Integer total = mapper.countTotal(baseQuery);
        if(total==0) return new PageInfo<>();
        List<T> ts = mapper.queryPage(baseQuery);
        return new PageInfo<>(total,ts);
    }


    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }
}
